<?php

namespace App\Models\Member;

use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

/**
 * App\Models\Member\Member
 *
 * @property int $id
 * @property string $password 密码
 * @property string|null $nick_name 昵称
 * @property string|null $mobile 手机
 * @property string|null $email 邮箱
 * @property string|null $avatar 用户头像
 * @property string $cash 现金
 * @property string|null $qq QQ
 * @property string|null $wechat 微信
 * @property int $status 1禁止,2正常
 * @property string|null $last_ip 最后登录IP
 * @property int|null $login_count 登录次数
 * @property string|null $last_login 最后登录时间
 * @property int $deleted 删除
 * @property string|null $remember_token 记住登录状态
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Chat\Friend[] $friend
 * @property-read int|null $friend_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Chat\GroupUser[] $group
 * @property-read int|null $group_count
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
 * @property-read int|null $notifications_count
 * @method static \Illuminate\Database\Eloquent\Builder|Member newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Member newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Member query()
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereAvatar($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereCash($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereDeleted($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereLastIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereLastLogin($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereLoginCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereNickName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereQq($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereRememberToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereWechat($value)
 * @mixin \Eloquent
 */
class Member extends Authenticatable {
	use HasFactory, Notifiable;

	protected function serializeDate( DateTimeInterface $date ) {
		return Carbon::instance( $date )->toDateTimeString();//这里使用toDateTimeString，不受Carbon中时区的影响
	}

	protected $table = 'member';
	protected $primaryKey = 'id';
	public $timestamps = true;
	protected $fillable = [
		//   'username',
		'email',
		'password',
		'mobile',
		'nick_name',
		'avatar',
		'status',
		'cash',
		'qq',
		'wechat',
		'last_ip',
		'last_login',
		'deleted',
		'remember_token',
	];

	protected $hidden = [
		'password',
		'remember_token',
	];

//    protected $casts = [
//        'email_verified_at' => 'datetime',
//    ];

	//好友关系表
	public function friend() {
		return $this->hasMany( 'App\Models\Chat\Friend', 'user_id', 'id' );
	}

	//群组关系表
	public function group() {
		return $this->hasMany( 'App\Models\Chat\GroupUser', 'user_id', 'id' );
	}

}
